package com.bwie.pojo;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

@Data
public class BasePojo  implements Serializable{
    /**
     * 创建人
     */
    private String createdBy;

    /**
     * 创建时间
     */
    private Date createdTime;

    /**
     * 更新人
     */
    private String updatedBy;

    /**
     * 更新时间
     */
    private Date updatedTime;

    public void readyCreated(String token){
        if (token==null){
            this.createdBy="未知";
        }else {
            Claims body = Jwts.parser().setSigningKey("123456").parseClaimsJws(token).getBody();
            Integer userId = body.get("userId", Integer.class);
            this.createdBy= ""+userId;
        }
        this.createdTime=new Date();
    }

    public void readyUpdated(String token){
        if (token==null){
            this.updatedBy="未知";
        }else {
            Claims body = Jwts.parser().setSigningKey("123456").parseClaimsJws(token).getBody();
            Integer userId = body.get("userId", Integer.class);
            this.updatedBy= ""+userId;
        }
        this.updatedTime=new Date();
    }
}
